package offer;
//从上往下打印二叉树
import com.springinaction.ch04.aopargs.TrackCounter;

import java.util.ArrayList;

public class T23 {

     public class TreeNode {
     int val = 0;
     TreeNode left = null;
     TreeNode right = null;

     public TreeNode(int val) {
     this.val = val;

     }

     }
    public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) {

          ArrayList<Integer> list = new ArrayList<Integer>();
          if (root==null) return list;
          TreeNode treeNode[] = new TreeNode[300];
          int l = 0;
          int r = 1;
          treeNode[0] = root;

          while (l<r) {
              list.add(treeNode[l].val);
              if (treeNode[l].left!=null) treeNode[r++]=treeNode[l].left;
              if (treeNode[l].right!=null) treeNode[r++]=treeNode[l].right;
              l++;
          }
         return list;
    }

}
